﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch04
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            /*
            //往选项卡组件中添加一页
            tabControl1.TabPages.Add("外观");

            //tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(new TextBox());
            
            //获取总页数
            int count = tabControl1.TabPages.Count;

            //获取最后一页
            TabPage page = tabControl1.TabPages[count - 1];
            page.BackColor = Color.White;

            //创建一个文本框
            TextBox txt = new TextBox();
            txt.Font = new Font("宋体",20);
            txt.Size = new Size(300,50);

            //往最后一页添加控件
            page.Controls.Add(txt);
            */
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取选中项的文本
            string item = listBox1.SelectedItem.ToString();

            //页面的name属性作为key，进行判断是否包含某个页面
            if (!tabControl1.TabPages.ContainsKey(item))
            {
                //创建选项卡页面对象
                TabPage page = new TabPage(item);
                page.Name = item;
                page.BackColor = Color.White;

                //将页面添加到选项卡控件中
                tabControl1.TabPages.Add(page);

                //让当前添加的页面成为选中页
                tabControl1.SelectedTab = page;
            }
        }
    }
}
